home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / cnumber.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.4 KB  |  192 lines

  1. //$Id: cnumber.cc 1.3 1997/07/14 04:19:43 dlorre Exp dlorre $
  2. #include <graphics/gfxmacros.h>
  3. #include <intuition/intuition.h>
  4. #include <intuition/classes.h>
  5. #include <intuition/classusr.h>
  6. #include <intuition/imageclass.h>
  7. #include <intuition/gadgetclass.h>
  8. #include <intuition/icclass.h>
  9. #include <intuition/cghooks.h>
  10. #include <libraries/gadtools.h>
  11.  
  12. #include <string.h>
  13. #include <stdio.h>
  14. #include <mydebug.h>
  15.  
  16. #include "screen.h"
  17. #include "window.h"
  18. #include "gadgets/cnumber.h"
  19. #include "gadgets/eclass.h"
  20. #include "gadgetlist.h"
  21.  
  22. #include <proto/exec.h>
  23. #include <proto/graphics.h>
  24. #include <proto/intuition.h>
  25. #include <proto/utility.h>
  26. #include <clib/alib_protos.h>
  27.  
  28. IMPORT Class *BOOPSIELabel ;
  29. IMPORT int InitELabel(void) ;
  30. IMPORT void FreeELabel(void) ;
  31.  
  32.  
  33. // ========================================================================
  34. // ==========================  CNUMBER CLASS ==============================
  35. // ========================================================================
  36. cnumber::cnumber(gadgetlist *gl,
  37.                  void (window::*func)(gadget *, unsigned long, unsigned short),
  38.                  const char *t,
  39.                  long val,
  40.                  long border, long place, char style) : gadget(gl, func)
  41. {
  42. int i, l1, l2 ;
  43. BOOL underset = FALSE ;
  44. UWORD *pens = gl->win->ws->drawinfo->dri_Pens;
  45. short gleft, gtop, gwidth, gheight ;
  46.  
  47.     gl->ng->ng_Flags = place ;
  48.     InitELabel() ;
  49.  
  50.     gleft = gl->ng->ng_LeftEdge ;
  51.     gtop = gl->ng->ng_TopEdge ;
  52.     gwidth = gl->ng->ng_Width ;
  53.     gheight = gl->ng->ng_Height ;
  54.  
  55.     if (style & BOTTOMCNUMBER)
  56.         gtop = short(-gtop) ;
  57.     if (style & RIGHTCNUMBER)
  58.         gleft = short(-gleft) ;
  59.     if (style & WIDTHCNUMBER)
  60.         gwidth = short(-gwidth) ;
  61.     if (style & HEIGHTCNUMBER)
  62.         gheight = short(-gheight) ;
  63.  
  64.  
  65.     if (t) {
  66.  
  67.         it1 = new IntuiText ;
  68.         it2 = new IntuiText ;
  69.         it3 = new IntuiText ;
  70.  
  71.         plain = new TTextAttr ;
  72.         underline = new TTextAttr ;
  73.  
  74.         it1->FrontPen = it2->FrontPen = it3->FrontPen = gl->win->ws->drawinfo->dri_Pens[(place&NG_HIGHLABEL)?HIGHLIGHTTEXTPEN:TEXTPEN] ;
  75.         it1->BackPen = it2->BackPen = it3->BackPen = 0 ;
  76.         it1->DrawMode = it2->DrawMode = it3->DrawMode = JAM1 ;
  77.  
  78.         norm1 = new char[strlen(t)+1] ;
  79.         norm2 = new char[strlen(t)+1] ;
  80.         under = new char[2] ;
  81.  
  82.         underkey(t) ;
  83.  
  84.         CopyMem(gl->win->ws->scr->Font, plain, sizeof(struct TTextAttr)) ;
  85.         CopyMem(gl->win->ws->scr->Font, underline, sizeof(struct TTextAttr)) ;
  86.         underline->tta_Style |= FSF_UNDERLINED ;
  87.         font = OpenFont((TextAttr *)underline) ;
  88.  
  89.         for (i=l1=l2=0; t[i]; i++) {
  90.             if (t[i] == '_') {
  91.                 if (t[i+1]) under[0] = t[++i] ;
  92.                 underset = TRUE ;
  93.             }
  94.             else {
  95.                 if (underset) {
  96.                     norm2[l2++] = t[i] ;
  97.                 }
  98.                 else {
  99.                     norm1[l1++] = t[i] ;
  100.                 }
  101.             }
  102.         }
  103.         norm1[l1] = '\0' ;
  104.         norm2[l2] = '\0' ;
  105.         under[1] = '\0' ;
  106.  
  107.         if (l1) {
  108.             it1->IText = (UBYTE *)norm1 ;
  109.             it1->ITextFont = (TextAttr *)plain ;
  110.             if (underset) {
  111.                 it1->NextText = it2 ;
  112.                 it2->LeftEdge = short(IntuiTextLength(it1)) ;
  113.                 it2->IText = (UBYTE *)under ;
  114.                 it2->ITextFont = (TextAttr *)underline ;
  115.                 if (l2) {
  116.                     it2->NextText = it3 ;
  117.                     it3->LeftEdge = short(it2->LeftEdge + IntuiTextLength(it2)) ;
  118.                     it3->IText = (UBYTE *)norm2 ;
  119.                     it3->ITextFont = (TextAttr *)plain ;
  120.                 }
  121.             }
  122.         }
  123.         else if (underset) {
  124.             it1->IText = (UBYTE *)under ;
  125.             it1->ITextFont = (TextAttr *)underline ;
  126.             it1->NextText = it2 ;
  127.             it2->LeftEdge = short(IntuiTextLength(it1)) ;
  128.             it2->IText = (UBYTE *)norm2 ;
  129.             it2->ITextFont = (TextAttr *)plain ;
  130.         }
  131.     }
  132.     gad = gl->gad = (Gadget *)NewObject(BOOPSIELabel, NULL,
  133.             GA_ID,          id,
  134.             GA_Top,         gtop,
  135.             GA_Left,        gleft,
  136.             GA_Width,       gwidth,
  137.             GA_Height,      gheight,
  138.  
  139.             (style & BOTTOMCNUMBER)?GA_RelBottom:TAG_IGNORE,   TRUE,
  140.             (style & RIGHTCNUMBER)?GA_RelRight:TAG_IGNORE,     TRUE,
  141.             (style & WIDTHCNUMBER)?GA_RelWidth:TAG_IGNORE,     TRUE,
  142.             (style & HEIGHTCNUMBER)?GA_RelHeight:TAG_IGNORE,   TRUE,
  143.  
  144.  
  145.             GA_Previous,    gl->gad,
  146.             GA_IntuiText,   it1 ,
  147.             GA_Border,      border,
  148.             GA_Text,        val,
  149.             EGA_Flags,      place,
  150.             EGA_TextAttr,   gl->ng->ng_TextAttr,
  151.             EGA_XPens,      gl->win->ws->xpens,
  152.             EGA_GPen,       gl->gpen,
  153.             EGA_Number,     val,
  154.  
  155.             TAG_END) ;
  156. }
  157.  
  158. cnumber::~cnumber()
  159. {
  160.     if (norm1) delete norm1 ;
  161.     if (norm2) delete norm2 ;
  162.     if (under) delete under ;
  163.  
  164.     if (it1) delete it1 ;
  165.     if (it2) delete it2 ;
  166.     if (it3) delete it3 ;
  167.  
  168.     if (plain) delete plain ;
  169.     if (underline) delete underline ;
  170.  
  171.     if (gad) DisposeObject(gad) ;
  172.     if (font) CloseFont(font) ;
  173.     FreeELabel() ;
  174. }
  175.  
  176. void cnumber::set(LONG val)
  177. {
  178.     SetGadgetAttrs((Gadget *)gad, w, NULL,
  179.         EGA_Number,    val,
  180.         TAG_END) ;
  181. }
  182.  
  183. void cnumber::keystroke(BOOL shifted)
  184. {
  185.     if (gfunc)
  186.         gadget::action(NULL, 0) ;
  187.     else
  188.         glist->selectgadget(id+1, shifted) ;
  189. }
  190.  
  191.  
  192.